package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.OaHumanTransfer;
import com.ruoyi.oa.domain.vo.OaHumanTransferVo;
import com.ruoyi.oa.domain.bo.OaHumanTransferBo;
import com.ruoyi.oa.service.IOaHumanTransferService;
import com.ruoyi.common.core.page.TableDataInfo;


/**
 * 岗位调转申请
 *
 * @author ruoyi
 * @date 2023-06-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/humanTransfer")
public class OaHumanTransferController extends BaseController {

    private final IOaHumanTransferService iOaHumanTransferService;

    /**
     * 查询岗位调转申请列表
     */
    @SaCheckPermission("oa:employeeInfo:list")
    @GetMapping("/list")
    public TableDataInfo<OaHumanTransferVo> list(OaHumanTransferBo bo, PageQuery pageQuery) {
        return iOaHumanTransferService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出岗位调转申请列表
     */
    @Log(title = "岗位调转申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaHumanTransferBo bo, HttpServletResponse response) {
        List<OaHumanTransferVo> list = iOaHumanTransferService.queryList(bo);
        ExcelUtil.exportExcel(list, "岗位调转申请", OaHumanTransferVo.class, response);
    }

    /**
     * 获取岗位调转申请详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("oa:employeeInfo:query")
    @GetMapping("/{id}")
    public R<OaHumanTransferVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iOaHumanTransferService.queryById(id));
    }

    /**
     * 新增岗位调转申请
     */
    @SaCheckPermission("oa:employeeInfo:add")
    @Log(title = "岗位调转申请", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<OaHumanTransferBo> add(@Validated(AddGroup.class) @RequestBody OaHumanTransferBo bo) {
        return R.ok(iOaHumanTransferService.insertByBo(bo));
    }

    /**
     * 修改岗位调转申请
     */
    @SaCheckPermission("oa:employeeInfo:edit")
    @Log(title = "岗位调转申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<OaHumanTransfer> edit(@Validated(EditGroup.class) @RequestBody OaHumanTransferBo bo) {
        return R.ok(iOaHumanTransferService.updateByBo(bo));
    }

    /**
     * 删除岗位调转申请
     *
     * @param ids 主键串
     */
    @SaCheckPermission("oa:humanTransfer:remove")
    @Log(title = "岗位调转申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iOaHumanTransferService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
